using System;
using System.Collections.Generic;
using System.Text;
using AdobePhotoElementsMetatagger.ElementsDSTableAdapters;
using System.Collections.ObjectModel;

namespace AdobePhotoElementsMetatagger
{
    class ElementsHelper
    {
        private ElementsTagHelper _tagHelper;
        private ElementsDS _elementsDS;
        private ImageTableAdapter _imageTableAdapter;
        private FolderTableAdapter _folderTableAdapter;

        public ElementsHelper()
        {
            _elementsDS = new ElementsDS();
            _imageTableAdapter = new ImageTableAdapter();
            _folderTableAdapter = new FolderTableAdapter();
        }

        public void ConnectToElements()
        {
            CreateTags();
        }

        public void ProcessPictures()
        {
            _imageTableAdapter.Fill(_elementsDS.ImageTable);
            //_imageTableAdapter.FillByPath(_elementsDS.ImageTable, @"path to photos");
            foreach (ElementsDS.ImageTableRow imageRow in _elementsDS.ImageTable)
            {
                ElementsPictureHelper picHelper = new ElementsPictureHelper(imageRow);
                _tagHelper.AddTagsToPicture(picHelper.Picture, picHelper.TagIds);
                Console.WriteLine("Processing {0}", picHelper.Picture.FullFileName);
                try
                {
                    picHelper.UpdateMetaData();
                }
                catch { Console.WriteLine("Not valid jpg"); }
            }
        }

        private void CreateTags()
        {
            _tagHelper = new ElementsTagHelper(_folderTableAdapter.GetData());
        }

    }
}
